<?php

namespace app\api\controller;

use app\api\service\LoginService;
use app\api\service\ProductService;
use app\BaseController;
use app\Response;
use think\facade\Request;

class Product extends BaseController
{
    /** 产品列表
     * @return json
    */
    public function productList(){
        $user_id = LoginService::getUserIdFromToken();
        $page = Request::post("page",1);
        $num = Request::post("num",10);
        $key = Request::post("keyword","");
        $type = Request::post("type","");//1品牌专区 2秒杀专区 3预售专区
        $fs_up_status = Request::post("fs_up_status","");//是否秒杀
        $brand_up_status = Request::post("brand_up_status","");//是否品牌置顶
        $pre_up_status = Request::post("pre_up_status","");//是否品牌置顶
        $class_one  = Request::post("class_one","");
        $class_two  = Request::post("class_two","");
        $price_sort = Request::post("price_sort","");//1从低到高 2从高到低
        $commission_sort = Request::post("commission_sort");//1从低到高 2从高到低
        $br_id = Request::post("br_id");
        $material = Request::post("material","");
        list($data,$count) = ProductService::productList($user_id,$page,$num,$key,$type,$class_one,$class_two,$price_sort,$commission_sort,$fs_up_status,$brand_up_status,$pre_up_status,$br_id,$material);
        return Response::wrapData($data,$count);
    }


    /** 品牌列表
     * @return json
     */
    public function brandList(){
        $page = Request::post("page",1);
        $num = Request::post("num",10);
        $res = ProductService::productBrandList($page,$num);
        return $res;
    }

    /** 分类列表
     * @return json
    */
    public function classList(){
        $page = Request::post("page",1);
        $num = Request::post("num",10);
        $superior_id = Request::post("superior_id",0);
        $res = ProductService::categoryList($page,$num,$superior_id);
        return $res;
    }
    /** 产品详情
     * @return json
     */
    public function procutInfo(){
        $id = Request::post("id","");
        if (empty($id)){
            return Response::wrapError("信息异常!");
        }
        $user_id = LoginService::getUserIdFromToken();
        $info = ProductService::productDetailed($user_id,$id);
        return Response::wrapData($info);
    }


    public function evaluateList(){
        $id = Request::post("id",0);
        $sku_id = Request::post("sku_id",0);//子商品ID
        $page = Request::post("page",1);
        $num = Request::post("num",10);
        $order_type = Request::post("order_type",1);
        list($list,$count) = ProductService::productEvaluateList($id,$page,$num,$order_type,$sku_id);
        return Response::wrapData($list,$count);
    }
}